package com.vrv.app.cyberspace.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.vrv.app.cyberspace.common.utils.JSONResult;
import com.vrv.app.cyberspace.modules.sys.entity.FeedbackTable;
import com.vrv.app.cyberspace.modules.sys.entity.UserTable;
import com.vrv.app.cyberspace.modules.sys.mapper.FeedbackTableMapper;
import com.vrv.app.cyberspace.modules.sys.mapper.UserTableMapper;
import com.vrv.app.cyberspace.modules.sys.service.IFeedbackTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

import static com.vrv.app.cyberspace.common.utils.JSONResult.renderSuccess;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author sm
 * @since 2017-12-15
 */
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@Service
public class FeedbackTableServiceImpl extends ServiceImpl<FeedbackTableMapper, FeedbackTable> implements IFeedbackTableService {

    @Autowired
    private FeedbackTableMapper feedbackTableMapper;
    @Autowired
    private UserTableMapper userTableMapper;

    @Override
    public JSONResult summaryFeedback(FeedbackTable feedbackTable) {
        Page<FeedbackTable> page = new Page<>(feedbackTable.getPage(), feedbackTable.getSize());
        Wrapper<FeedbackTable> ew = new EntityWrapper<FeedbackTable>()
                .eq("reportID", feedbackTable.getReportID())
                .eq("isSubmit", feedbackTable.getIsSubmit());
        page.setRecords(feedbackTableMapper.selectPage(page, ew));
        return renderSuccess(page);
    }

    @Override
    @Transactional
    public boolean updateFeedback(FeedbackTable feedbackTable) {
        UserTable userTable = userTableMapper.selectById(feedbackTable.getWriterID());
        if (userTable != null) {
            feedbackTable.setFeedbackUnit(userTable.getOrgName());
            feedbackTable.setWriterName(userTable.getLinkdoodName());
            feedbackTable.setWritingTime(new Date());
            feedbackTable.setWriterPhone(userTable.getCellphone());
            return feedbackTableMapper.updateById(feedbackTable) > 0;
        }
        return false;
    }
}
